narrow_cast.hpp
namespace type_safe
{
template <typename Target, typename Source>
constexpr Target narrow_cast(const Source& source) noexcept;
template <typename Target, typename Source, class Policy>
constexpr 'hidden' narrow_cast(const integer<Source, Policy>& source) noexcept;
template <typename Target, typename Source>
constexpr 'hidden' narrow_cast(const floating_point<Source>& source) noexcept;
}
type_safe::narrow_cast
[types]template <typename Target, typename Source>
constexpr Target narrow_cast(const Source& source) noexcept;
Returns: An arithmetic type with the same value as in source
, but converted to to a different type.
Requires: The value of source
must be representable by the new target type.
type_safe::narrow_cast
[types]template <typename Target, typename Source, class Policy>
constexpr 'hidden' narrow_cast(const integer<Source, Policy>& source) noexcept;
Returns: A ts::integer with the same value as source
but of a different type.
Requires: The value of source
must be representable by the new target type.
Notes: Target
can either be a specialization of the integer
template itself or a built-in integer type, the result will be wrapped if needed.
type_safe::narrow_cast
[types]template <typename Target, typename Source>
constexpr 'hidden' narrow_cast(const floating_point<Source>& source) noexcept;
Returns: A ts::floating_point with the same value as source
but of a different type.
Requires: The value of source
must be representable by the new target type.
Notes: Target
can either be a specialization of the floating_point
template itself or a built-in floating point type, the result will be wrapped if needed.